﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebChat.Models
{
    public class MessageFormViewModel
    {
        private MessageRepository messageRep;
        private ChannelRepository channelRep;
        private UserRepository userRep;

        public Chatroom chat { get; set; }                          //Ett chat rom
        public aspnet_User owner { get; set; }                      //Eier av rommet
        public aspnet_User currentUser { get; set; }                //Denne brukeren
        public List<UsersInChatroom> usersInChatroom { get; set; }  //Liste med aktive brukere i chatten
        public Message mess { get; set; }

        /// <summary>
        /// Kontruktør
        /// </summary>
        /// <param name="id">chat id</param>
        public MessageFormViewModel(int id) 
        {
            userRep = new UserRepository();
            messageRep = new MessageRepository();
            channelRep = new ChannelRepository();
            chat = channelRep.showChatroom(id);
            owner = userRep.getOwner(channelRep.showChatroom(id));
            
        }

        /// <summary>
        /// Kontruktør
        /// </summary>
        /// <param name="id">chat id</param>
        /// <param name="userId">bruker id</param>
        public MessageFormViewModel(int id, Guid userId)
        {
            userRep = new UserRepository();
            messageRep = new MessageRepository();
            channelRep = new ChannelRepository();
            chat = channelRep.showChatroom(id);
            owner = userRep.getOwner(channelRep.showChatroom(id));
            currentUser = userRep.showUser(userId);
            usersInChatroom = userRep.getUsersInChatroom(id);
        }

    }
}